module cmd_exe(
    input clk,
    input rst_n,
    //发送指令
    output reg         tx_cmd_valid ,
    output reg [15:0]  tx_cmd_index ,//指令
    output reg [31:0]  tx_par_index ,//参数
    //接收指令
    input              rx_cmd_valid ,
    input  [15:0]      rx_cmd_index ,//指令
    input  [31:0]      rx_par_index ,//参数
    //用户接口0:温度上报
	 input [19:0]       temp_data    ,//温度绝对值
	 input              sign         ,//温度符号
	 //用户接口1:温度阈值
	 output [19:0]      thr_data     ,//温度阈值的绝对值
	 output             thr_sign      //温度阈值符号
    //...
);
parameter CLK_FREQ  = 50_000_000;//系统时钟频率
assign thr_data = thr_data_r;
assign thr_sign = thr_sign_r;
//温度上报
reg [31:0] temp_cnt  ;
reg        temp_valid;
always@(posedge clk or negedge rst_n) begin
if(~rst_n) 
	temp_cnt <= 0;
else       
	temp_cnt <= (temp_cnt >= CLK_FREQ-1)?0:temp_cnt+1;
end
always@(posedge clk or negedge rst_n) begin
if(~rst_n) 
	temp_valid <= 1'b0;
else       
	temp_valid <= (temp_cnt == 0);
end
always@(posedge clk or negedge rst_n) 
begin
if(~rst_n) begin
    tx_cmd_valid <= 1'b0 ;
    tx_cmd_index <= 16'd0;
    tx_par_index <= 32'd0;
end
else begin
    if(temp_valid) begin
        tx_cmd_valid <= 1'b1                      ;
        tx_cmd_index <= 16'h8000                  ;
        tx_par_index <= {7'd0,sign,4'd0,temp_data};
    end
    else begin
        tx_cmd_valid <= 1'b0        ;
        tx_cmd_index <= tx_cmd_index;
        tx_par_index <= tx_par_index;
    end
end
end
//温度阈值
reg [19:0] thr_data_r;
reg        thr_sign_r;
always@(posedge clk or negedge rst_n) 
begin
if(~rst_n) begin
    thr_data_r <= 20'h009C4;//十进制2500，代表25摄氏度
    thr_sign_r <= 1'b0 ;
end
else begin
    if(rx_cmd_valid && (rx_cmd_index == 16'h8001)) begin
		thr_data_r <= rx_par_index[19:0];
		thr_sign_r <= rx_par_index[24]  ;
    end
    else begin
		thr_data_r <= thr_data_r;
		thr_sign_r <= thr_sign_r;
    end
end
end
endmodule